package com.soft.javase.day11.recursion;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/5/9
 */
public class BeerDrink {
    public static void main(String[] args) {
        int money = 10;
        int price = 2;
        int Beers = money / price;

        int total = drinkBeer(Beers, Beers, Beers);
        System.out.println("10元钱最多可以喝 " + total + " 瓶啤酒");
    }


    public static int drinkBeer(int total, int bottles, int caps) {
        int exchangeByBottle = bottles / 2;
        int exchangeByCap = caps / 4;

        if (exchangeByBottle == 0 && exchangeByCap == 0) {
            return total;
        }

        int newBeers = exchangeByBottle + exchangeByCap;

        int newBottles = bottles % 2 + newBeers;

        int newCaps = caps % 4 + newBeers;

        return drinkBeer(total + newBeers, newBottles, newCaps);
    }
}
